//
// Unihan Input Method
//
// Copyright © 2002-2007 Sun Wah Linux Ltd.
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
// USA
//
// $Id: IMAdd_cb.c 757 2007-05-10 08:19:31Z roger $
//

#include <gtk/gtk.h>
#include <string.h>
#include <gconf/gconf-client.h>

#include "IMAdd_cb.h"
#include "prefedit.h"
#include "list_ctrl.h"
#include "list_factory.h"

void
on_IM_All_Tree_View_Selection_changed(GtkTreeSelection *selection,
		gpointer data)
{
	GtkWidget *w;
	GtkTreeIter iter;
	GtkTreeModel *model;
	gchar *id = NULL;

	w = glade_xml_get_widget(xml_IMAdd, "buttonIMAllAdd");

	if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
		GList *l_curr = im_curr_list;
		IMInfo *info_curr;
		gtk_tree_model_get(model, &iter,
				STORE_2, &id,
				-1);
		while (l_curr) {
			info_curr = (IMInfo *)l_curr->data;
			if (strcmp(id, info_curr->id) == 0)
				break;
			l_curr = g_list_next(l_curr);
		}
		if (l_curr)
		//zzc
		{
			
			gtk_widget_set_sensitive(w, FALSE);
		//	GtkWidget *dialog;
		//	GtkMessageType type;
		//	gchar *message;
		//	message="此输入法已经添加，不可以再次添加!";
		//	type=GTK_MESSAGE_WARNING;
		//	dialog=gtk_message_dialog_new(NULL,
		//			GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
		//			type,
		//			GTK_BUTTONS_OK,
		//			message);
		//	gtk_dialog_run(GTK_DIALOG(dialog));
		//	gtk_widget_destroy(dialog);
		//	gtk_widget_set_sensitive(w, TRUE);
		}
		else
			gtk_widget_set_sensitive(w, TRUE);
	}
}

void
on_IM_All_Button_Add_clicked(GtkButton *button, gpointer data)
{
	GtkWidget *w;
	GtkTreeSelection *selection;
	GtkTreeIter iter;
	GtkTreeModel *model;
	gchar *id;
	GConfClient *client = gconf_client_get_default();

	w = glade_xml_get_widget(xml_IMAdd, "treeviewIMAll");
	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));

	if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
		gtk_tree_model_get(model, &iter,
				STORE_2, &id,
				-1);
		gconf_client_set_string(client,
				STATUS_IM_ADD_KEY,
				id,
				NULL);
	}

	w = glade_xml_get_widget(xml_IMAdd, "windowIMAdd");
	g_object_unref(G_OBJECT(xml_IMAdd));
//zzc
		gtk_widget_destroy(w);
//zzc
}

void
on_IM_All_Button_Cancel_clicked(GtkButton *button, gpointer data)
{
	GtkWidget *w;

	w = glade_xml_get_widget(xml_IMAdd, "windowIMAdd");
	g_object_unref(G_OBJECT(xml_IMAdd));
	gtk_widget_destroy(w);
}

void
on_IM_All_Window_destroy(GtkWidget *widget, gpointer data)
{
	g_object_unref(G_OBJECT(xml_IMAdd));
	gtk_widget_destroy(widget);
}

// vi:ts=4:nowrap:cin:expandtab
